<%--***************************************
*
*云网支付
sample data return from cncard payment
---------------------------------------
Name:[c_memo2] Value:[020]
Name:[c_orderamount] Value:[0.10]
Name:[c_succmark] Value:[Y]
Name:[c_ymd] Value:[20060817]
Name:[c_mid] Value:[1008433]
Name:[c_moneytype] Value:[0]
Name:[c_transnum] Value:[2546177]
Name:[c_memo1] Value:[12]
Name:[c_signstr] Value:[3566b9bb9a8166d03866dd845504c07b]
Name:[c_paygate] Value:[1]
Name:[c_order] Value:[020]
Name:[c_cause] Value:[succ]
----------------------------------------

* 
***************************************--%>
<%@ page import="
	java.math.BigDecimal,
	com.probiz.estore.system.util.TranslateService,
	com.probiz.estore.Constants,
	com.probiz.estore.order.model.OnlinePaymentResponse,
	com.probiz.estore.common.model.system.PaymentGateway,
	com.probiz.estore.system.service.PaymentGatewayManager,
	com.probiz.estore.common.service.OrderService,
	org.springframework.web.context.support.WebApplicationContextUtils,
	org.springframework.web.context.WebApplicationContext"
	pageEncoding="UTF-8"%>
	
<%
	
	WebApplicationContext webAppContext=WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
	PaymentGatewayManager paymentGatewayManager=(PaymentGatewayManager)webAppContext.getBean("paymentGatewayManager");
	PaymentGateway paymentGateway=paymentGatewayManager.getByPaymentGatewayCode("cncard");
	String c_pass=paymentGateway.getConfigData().get("c_pass").toString();

	String c_mid=request.getParameter("c_mid");
	String c_order=request.getParameter("c_order");
	String orderNo = c_order;
	String amount=request.getParameter("c_orderamount");
	String c_ymd=request.getParameter("c_ymd");
	String c_transnum=request.getParameter("c_transnum");
	String c_succmark=request.getParameter("c_succmark");
	String c_moneytype=request.getParameter("c_moneytype");
	String c_memo1=request.getParameter("c_memo1");
	String c_memo2=request.getParameter("c_memo2");
	String c_signstr1=request.getParameter("c_signstr");

	
	StringBuffer originalText = new StringBuffer();
	originalText.append(c_mid).append(c_order).append(amount).append(c_ymd).append(c_transnum).append(c_succmark)
				.append(c_moneytype).append(c_memo1).append(c_memo2).append(c_pass);
	String c_signstr2=TranslateService.md5Translate(originalText.toString());
	
	Short flag=null;
	if(c_signstr1.equals(c_signstr2)){//present the data is really come from cncard payment gateway.
		if(c_succmark.equalsIgnoreCase("Y")){//present the order is pay for successfully
			flag = Constants.PAYMENT_HISTORY_FLAG_SUCCESS;
		}
	}
	
	OnlinePaymentResponse onlinePaymentResponse = new OnlinePaymentResponse();
	onlinePaymentResponse.setFlowNo(c_order); //必填. 如果支付网关没有流水号，则使用原始的orderNo，即未decode前的
	onlinePaymentResponse.setOrderNo(orderNo); //必填
	onlinePaymentResponse.setFlag(flag);  //必填
	onlinePaymentResponse.setAmount(new BigDecimal(amount)); //必填
	onlinePaymentResponse.setPaymentGateway(paymentGateway); //必填
	OrderService orderService = (OrderService) webAppContext.getBean("orderService");
	request.setAttribute("onlinePaymentResponse",onlinePaymentResponse);
	orderService.doHandleOnlinePaymentResponse(onlinePaymentResponse,request);
%>


<%@include file="./include/finishPayResult.jspf"%>
